﻿@model  IPagedList<Models.DataModel.UserAccount>
@using PagedList
@using PagedList.Mvc
@using Models.DataModel;
@using Models.DataStore;
@{
    ViewBag.Title = "List User Account";
    Layout = "~/Views/Shared/_Layout.cshtml";
    int x = 0;
}
<div>

</div>
<br />
@using (Html.BeginForm("ListUserAccount", "UserAccount", FormMethod.Post, new { @class = "form-inline" }))
{
    <div class="form-group">
        <input type="text" class="form-control" id="searchtext" name="searchtext" placeholder="Please input value" value="@ViewBag.SearchText">
    </div>
    <button type="submit" class="btn btn-default">Search</button>
    <button type="button" class="btn btn-primary" onclick="location.href='@Url.Action("AddUser", "UserAccount")'">Add User</button>
    <a href="@Url.Action("ExportUserAccount","UserAccount")" class="btn btn-default">Export Excel</a>
}
<br />
<div class="table-responsive">
    <table class="table table-bordered table-hover table-condensed">
        <thead>
            <tr>
                <th>
                    <input id="ChkCheckFull" name="delall" type="checkbox" value="">
                    <button type="submit" id="btnCMS_Del_Cus" class="glyphicon glyphicon-trash" value="" onclick="return confirm('Are you sure you want to delete this item selected ?');" style="color:red; border:none; background:none"></button>
                </th>
                <th>UserName</th>
                <th>Full Name</th>
                <th>Birthday</th>
                <th>Email</th>
                <th>Gourp User Id</th>
                <th>CreateOn</th>
                <th>Active</th>
                <th></th>
                <th></th>
            </tr>
        </thead>
        <tbody>
            @{ int i = 0;
             foreach (var item in Model)
             {
                 i++;
                 var style = i % 2 == 0 ? "gradeA even" : "gradeA odd";
                <tr class="@style">
                    <td><input name="delvalue" type="checkbox" value="" class="checkCust" id="@item.UserAccountID"></td>
                    <td><a href="@Url.Action("Edituser", "UserAccount", new { UserId = item.UserAccountID })">@item.UserName</a></td>
                    <td>@item.FullName</td>
                    <td class="center sorting_1">@item.Birthday</td>
                    <td class="center">@item.Email</td>
                     @{
                        Models.DataStore.Ctrl fun = new Ctrl();
                        GroupUser ObjGroup = fun.GetobjGroupUserById(item.GroupUserID);
                     }
                    <td>@ObjGroup.GroupName</td>
                    <td>@item.CreatedOn</td>
                    <td>@item.Active</td>
                    <td>@Html.ActionLink("Delete", "DeleteUser", new { UserId = item.UserAccountID })</td>
                    @if(item.UserName == Session["user"].ToString())
                    {
                        <td>@Html.ActionLink("Change Password", "ChangePass", new { UserId = item.UserAccountID }) </td>   
                    }
                    else
                    {
                        <td></td>
                    }
                </tr>
             }
            }
        </tbody>
    </table>
</div>
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 padding nagavition">
    @if (Model.PageCount > 1)
    {
        @Html.PagedListPager(Model, page => Url.Action("ListUserAccount", new
        {
            page,
            searchtext = ViewBag.SearchText,
        }))
    }
</div>
<script>
    $("#ChkCheckFull").click(function () {
        if ($("#ChkCheckFull").is(':checked') == true) {
            $(".checkCust").prop('checked', true);
        }
        else {
            $(".checkCust").prop('checked', false);
        }

    });
    $("#btnCMS_Del_Cus").click(function () {
        var result = confirm('Xóa các khách hàng đã chọn?');
        if (result == true)
        {
            var lstData = "";
            $('.checkCust').each(function () {
                var sThisVal = (this.checked ? "1" : "0");
                if (sThisVal == 1) {
                    lstData += $(this).attr('id') + "|";
                }
            });
            $.post("../../UserAccount/DeleteUser", { UserId: lstData }, function (data) {
                if (data == "Fail") {
                    return;
                }
                window.location.href = '@Url.Action("ListUserAccount", "UserAccount")';
            });
        }
    });
</script>